#!/usr/bin/python
import struct
import os
import array
import sys

fn = ""

try:
    fn = sys.argv[1]
except:
    print "exception found! using soundrecord.wav"
    fn = "soundrecord.wav"

print "file:", fn

r = open(fn, 'rb')
data = r.read();
size = r.tell()/4;
print "size:", size

print "to: converted.wav"
s = struct.unpack(size*"L", data);
w = open("converted.wav", "wb");
step = 44100.0/8000.0
print "step:", step
pro = 0.0
n = []
i = 0
while(pro < size):
    n.append(s[int(pro)])
    pro += step
    i+=1

print "length of n:", len(n)
sn = struct.pack(i*"L", *n)
w.write(sn)
w.close()
